package com.patelski.magic.service;

import javax.ejb.Stateful;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.security.Restrict;

import com.patelski.common.service.AbstractSearchAction;
import com.patelski.magic.model.Edition;

@Stateful
@Name("editionLov")
@Scope(ScopeType.SESSION)
@Restrict("#{identity.loggedIn}")
public class EditionLovImpl extends AbstractSearchAction<Edition> implements
		EditionLov {

	private String searchName;

	protected void query() {
		String name = "".equals(searchName) ? "%" : '%' + searchName
				.toLowerCase() + '%';
		resultList = em.createQuery(
				"select edition from Edition edition where lower(edition.name) like \'"
						+ name + "\'").setMaxResults(pageSize).setFirstResult(
				page * pageSize).getResultList();
	}

	public String getSearchName() {
		return searchName;
	}

	public void setSearchName(String searchName) {
		this.searchName = searchName;
	}

}
